Write-Host "Starting ShowWorkflow Backend Service..." -ForegroundColor Green
Write-Host ""

# Check if Java is installed
try {
    java -version | Out-Null
    Write-Host "✓ Java found" -ForegroundColor Green
}
catch {
    Write-Host "✗ Error: Java not found. Please install Java first." -ForegroundColor Red
    pause
    exit 1
}

# Check if Maven is installed
try {
    mvn --version | Out-Null
    Write-Host "✓ Maven found" -ForegroundColor Green
}
catch {
    Write-Host "✗ Error: Maven not found. Please install Maven first." -ForegroundColor Red
    pause
    exit 1
}

Write-Host ""

# Check if target jar exists, if not compile first
$jarPath = "target/showworkflow-backend-1.0.0.jar"
if (-not (Test-Path $jarPath)) {
    Write-Host "JAR file not found. Compiling project..." -ForegroundColor Yellow
    mvn clean package -DskipTests
    
    if ($LASTEXITCODE -ne 0) {
        Write-Host "✗ Compilation failed. Please check error messages." -ForegroundColor Red
        pause
        exit 1
    }
    
    Write-Host "✓ Compilation successful" -ForegroundColor Green
}
else {
    Write-Host "✓ JAR file found, skipping compilation" -ForegroundColor Green
}

Write-Host ""

# Start service
Write-Host "Starting service on port 35005..." -ForegroundColor Green
java -jar $jarPath